/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.xcxAdmin.web;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.goods.entity.ZtAddr;
import com.jeesite.modules.goods.entity.ZtGoods;
import com.jeesite.modules.xcxAdmin.entity.ZtAdmin;
import com.jeesite.modules.xcxAdmin.entity.ZtWithdraw;
import com.jeesite.modules.xcxAdmin.service.ZtWithdrawService;

/**
 * 测试数据Controller
 * 
 * @author ThinkGem
 * @version 2018-04-22
 */
@Controller
@RequestMapping(value = "${adminPath}/ztWithdraw")
public class ZtWithdrawController extends BaseController {

	@Autowired
	private ZtWithdrawService ztWithdrawService;

	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ZtWithdraw get(String id, boolean isNewRecord) {
		ZtWithdraw ztWithdraw=new ZtWithdraw();
		ztWithdraw.setId(id);
		return ztWithdrawService.get(ztWithdraw);
	}

	/**
	 * 查询列表
	 */
	@RequestMapping(value = { "list", "" })
	public String list(ZtWithdraw ztWithdraw, Model model,HttpSession session) {
		if(ztWithdraw!=null && ztWithdraw.getZtAdmin()!=null && StringUtils.isNotBlank(ztWithdraw.getZtAdmin().getId())){
			session.setAttribute("ztWithdrawAdminid", ztWithdraw.getZtAdmin().getId());
		}else{
			if(ztWithdraw==null){ztWithdraw=new ZtWithdraw();}
			ZtAdmin ztAdmin=new ZtAdmin();
			ztAdmin.setId(session.getAttribute("ztWithdrawAdminid").toString());
			ztWithdraw.setZtAdmin(ztAdmin);
		}
		
		model.addAttribute("ztWithdraw", ztWithdraw);
		
		return "modules/ztWithdraw/ztWithdrawList";
	}

	/**
	 * 查询列表数据
	 */
	
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<ZtWithdraw> listData(ZtWithdraw ztWithdraw, HttpServletRequest request,
			HttpServletResponse response,Model model,HttpSession session) {
		
		session.getAttribute("ztAdminId");
		
		Page<ZtWithdraw> page = ztWithdrawService.findPage(new Page<ZtWithdraw>(request,
				response), ztWithdraw);
		
		
		return page;
	}

	/**
	 * 打款操作
	 */
	@RequiresPermissions("ztWithdraw:ztWithdrawData:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(ZtWithdraw ztWithdraw) {
		ztWithdraw.setIspay("1");
		ztWithdraw.setPayDate(new Date());
		ztWithdrawService.updateSjStatus(ztWithdraw);
		
		return renderResult(Global.TRUE, text("打款成功"));
	}
	
	
	
	/**
	 * 没有打款的提现
	 */
	@RequestMapping(value = "nopaymentlist")
	public String nopaymentlist(ZtWithdraw ztWithdraw, Model model) {
		
		model.addAttribute("ztWithdraw", ztWithdraw);
		
		return "modules/ztWithdraw/nopayztWithdrawList";
	}

	/**
	 * 没有提现的打款  列表数据
	 */
	@RequestMapping(value = "nopaymentlistData")
	@ResponseBody
	public Page<ZtWithdraw> nopaymentListData(ZtWithdraw ztWithdraw, HttpServletRequest request,
			HttpServletResponse response,Model model) {
		
		ztWithdraw.setIspay("0");
		
		Page<ZtWithdraw> page = ztWithdrawService.findPage(new Page<ZtWithdraw>(request,
				response), ztWithdraw);
		
		
		return page;
	}
	
	/**
	 * 已经打款记录
	 */
	@RequestMapping(value = "paymentlist")
	public String paymentlist(ZtWithdraw ztWithdraw, Model model,HttpSession session) {
		
		model.addAttribute("ztWithdraw", ztWithdraw);
		
		return "modules/ztWithdraw/payztWithdrawList";
	}

	/**
	 * 已经打款记录  列表数据
	 */
	
	@RequestMapping(value = "paymentlistData")
	@ResponseBody
	public Page<ZtWithdraw> paymentlistData(ZtWithdraw ztWithdraw, HttpServletRequest request,
			HttpServletResponse response,Model model,HttpSession session) {
		
		ztWithdraw.setIspay("1");
		
		Page<ZtWithdraw> page = ztWithdrawService.findPage(new Page<ZtWithdraw>(request,
				response), ztWithdraw);
		
		
		return page;
	}
	
}